package com.example.chuntiao.cophook.ui;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by chuntiao on 17-7-30.
 * 此处代码来自CSDN http://blog.csdn.net/lyltiger/article/details/51658120 lyltiger
 * 在我研究过　onInterceptTouchEvent　拦截机制后，做了更改
 */

public class MyRefreshLayout extends SwipeRefreshLayout {
    private int scaleTouchSlop;
    private float preX;
    private float preY;

    public MyRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:

                preX = ev.getX();
                preY = ev.getY();
                break;

            case MotionEvent.ACTION_MOVE:
                float moveX = ev.getX();
                float moveY = ev.getY();
                float instanceX = Math.abs(moveX - preX);
                float disY = Math.abs(moveY - preY);

                if (instanceX > disY) {
                    return false;//即当前控件（有viewGroup属性）不处理事件，将其传递给子控件
                }
                break;
        }
        return super.onInterceptTouchEvent(ev);
    }
}
